import xmlrpclib
import os
import codecs
import zlib

serAddr = 'http://10.155.32.188:9000'
rootDir = ''


proxy = xmlrpclib.ServerProxy(serAddr, allow_none=True)
rootDir = proxy.getRootDir()
if (rootDir==''):
    print('rootDir is null, default is share')
    rootDir = 'share'
    rootDir = os.path.abspath(rootDir)
try:
    os.stat(rootDir)
except(OSError):
    os.mkdir(rootDir)
print('rootdir=' + rootDir)

fileList = proxy.getFileList()
for file in fileList:
    print(file)
    data = proxy.getFile(file).data
    if (not data):
        print('data is null')
        continue
    #data = zlib.decompress(data)
    name = os.path.basename(file)
    path = os.path.dirname(file)
    lfile = os.path.join(rootDir, name)
    with codecs.open(lfile, mode='wb') as fp:
        fp.write(data)

